package cn.com.service.impl;

import java.util.List;

import static cn.com.support.message.MessageCodeEnum.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import cn.com.commons.Paginator;
import cn.com.dal.dao.OperationLogDAO;
import cn.com.dal.dataobject.OperationLogDO;
import cn.com.service.OperationLogService;
import cn.com.support.dal.DAOException;
import cn.com.support.message.MessageResult;

/**
 * OperationLogService实现类
 * 
 * @since 2012-3-6 下午9:26:49
 * @version 1.0
 * @author Microbun
 */
@Service
public class OperationLogServiceImpl implements OperationLogService {

	private Logger logger = LoggerFactory
			.getLogger(OperationLogServiceImpl.class);

	private OperationLogDAO<OperationLogDO> operationLogDAO;

	@Override
	public <C> Paginator<C, List<OperationLogDO>> selectByPage(
			Paginator<C, List<OperationLogDO>> paginator) {
		try {
			return operationLogDAO.selectForPage(paginator);
		} catch (DAOException e) {
			logger.error(
					String.format(ERROR_SELECT.descript() + ":[%s]", paginator.getCondition()), e);
		}
		return null;
	}

	@Override
	public MessageResult<Long> insert(OperationLogDO operationLogDO) {
		MessageResult<Long> result =  new MessageResult<Long>(true, null, ERROR_INSERT);
		try {
			Long id = operationLogDAO.insert(operationLogDO);
			if (id != null && id > 0) {
				result = new MessageResult<Long>(true, id, INFO_SUCCEED);
			}
		} catch (DAOException e) {
			logger.error(String.format(ERROR_INSERT.descript() + ":[%s]", operationLogDO), e);
		}
		return result;
	}

}
